package com.catchu.pattern.creational.迭代器模式.b进阶.aggregate;

import com.catchu.pattern.creational.迭代器模式.b进阶.iterator.ArrayPayIterator;
import com.catchu.pattern.creational.迭代器模式.b进阶.iterator.Iterator;
import com.catchu.pattern.creational.迭代器模式.b进阶.model.PayModel;

/**
 * 底层使用数组实现的聚合对象
 */
public class ArrayPayAggregate extends BasicAggregate{

    private PayModel[] payModels = new PayModel[2];

    @Override
    public Iterator createIterator() {
        return new ArrayPayIterator(this);
    }

    /**
     * 获取某个元素值
     * @param index
     * @return
     */
    public Object get(int index){
        Object result = null;
        if(index<this.payModels.length){
            result = this.payModels[index];
        }
        return result;
    }

    /**
     * 获取集合长度
     * @return
     */
    public int size(){
        return this.payModels.length;
    }

    /**
     * 获取工资列表
     * @return
     */
    public PayModel[] getList(){
        return this.payModels;
    }

    public void calcPay(){
        PayModel payModel = new PayModel();
        payModel.setName("王五");
        payModel.setSalary(3000.0);

        PayModel payModel2 = new PayModel();
        payModel2.setName("孙六");
        payModel2.setSalary(4208.2);

        payModels[0] = payModel;
        payModels[1] = payModel2;
    }
}
